home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_10_02
/
1002018a
< prev
next >
Wrap
Text File
|
1991-12-15
|
1KB
|
46 lines
Listing 6 -- the file xfspos.c
/* _Fspos function -- UNIX version */
#include <errno.h>
#include "xstdio.h"
/* UNIX system call */
long _Lseek(int, long, int);
int _Fspos(FILE *str, const fpos_t *ptr, long loff, int way)
{ /* position a file */
if (fflush(str))
{ /* write error */
errno = EFPOS;
return (EOF);
}
if (ptr)
loff += ((fpos_t *)ptr)->_Off; /* fsetpos */
if (way == SEEK_CUR && str->_Mode & _MREAD)
loff -= str->_Nback
? str->_Rsave - str->_Next + str->_Nback
: str->_Rend - str->_Next;
if (way == SEEK_CUR && loff != 0
|| way != SEEK_SET || loff != -1)
loff = _Lseek(str->_Handle, loff, way);
if (loff == -1)
{ /* request failed */
errno = EFPOS;
return (EOF);
}
else
{ /* success */
if (str->_Mode & (_MREAD|_MWRITE))
{ /* empty buffer */
str->_Next = str->_Buf;
str->_Rend = str->_Buf;
str->_Wend = str->_Buf;
str->_Nback = 0;
}
str->_Mode &= ~(_MEOF|_MREAD|_MWRITE);
return (0);
}
}